<template>
  <div class="case-layout">
    <!-- 顶部导航 -->
    <header class="case-header">
      <div class="header-content">
        <h1 class="logo">
          <RouterLink to="/home" class="logo-link">组件案例库</RouterLink>
        </h1>
        
        <!-- 二级菜单导航 -->
        <div class="nav-container">
          <!-- 首页链接 -->
          <RouterLink 
            to="/home" 
            class="nav-link"
            :class="{ active: $route.name === 'Home' }"
          >
            首页
          </RouterLink>
          
          <!-- LeeUI 二级菜单 -->
          <ElDropdown trigger="hover" placement="bottom">
            <div class="dropdown-link" :class="{ active: isLeeuiRoute }">
              LeeUI 组件
              <ElIcon class="icon-arrow">
                <ArrowDown />
              </ElIcon>
            </div>
            <template #dropdown>
              <ElDropdownMenu class="custom-dropdown-menu">
                <ElDropdownItem class="custom-dropdown-item">
                  <RouterLink to="/leeui/form" class="dropdown-item-link">表单 Form</RouterLink>
                </ElDropdownItem>
                <ElDropdownItem class="custom-dropdown-item">
                  <RouterLink to="/leeui/table" class="dropdown-item-link">表格 Table</RouterLink>
                </ElDropdownItem>
                <ElDropdownItem class="custom-dropdown-item">
                  <RouterLink to="/leeui/com" class="dropdown-item-link">单个组件 Com</RouterLink>
                </ElDropdownItem>
              </ElDropdownMenu>
            </template>
          </ElDropdown>
          
          <!-- Element 二级菜单 -->
          <ElDropdown trigger="hover" placement="bottom">
            <div class="dropdown-link" :class="{ active: isElementRoute }">
              Element 组件
              <ElIcon class="icon-arrow">
                <ArrowDown />
              </ElIcon>
            </div>
            <template #dropdown>
              <ElDropdownMenu class="custom-dropdown-menu">
                <ElDropdownItem class="custom-dropdown-item">
                  <RouterLink to="/element/form" class="dropdown-item-link">表单 Form</RouterLink>
                </ElDropdownItem>
                <ElDropdownItem class="custom-dropdown-item">
                  <RouterLink to="/element/table" class="dropdown-item-link">表格 Table</RouterLink>
                </ElDropdownItem>
              </ElDropdownMenu>
            </template>
          </ElDropdown>
        </div>
      </div>
    </header>

    <!-- 主要内容区 -->
    <main class="case-main">
      <div class="case-container">
        <!-- 页面标题 -->
        <div class="page-header">
          <h2 class="page-title">{{ $route.meta.title || '案例展示' }}</h2>
          <p class="page-desc">
            {{ isLeeuiRoute ? 'LeeUI 组件案例展示' : 'Element 组件案例展示' }}
          </p>
        </div>

        <!-- 案例内容 -->
        <div class="case-content">
          <router-view />
        </div>
      </div>
    </main>

    <!-- 页脚 -->
    <footer class="case-footer">
      <p>组件案例库 &copy; {{ new Date().getFullYear() }}</p>
    </footer>
  </div>
</template>

<script setup lang="ts">
import { useRoute } from 'vue-router'
import { computed } from 'vue'
import { ElDropdown, ElDropdownMenu, ElDropdownItem, ElIcon } from 'element-plus'
import { ArrowDown } from '@element-plus/icons-vue'
import { RouterLink } from 'vue-router'

const route = useRoute()

// 检查是否为 LeeUI 相关路由
const isLeeuiRoute = computed(() => {
  return typeof route.name === 'string' && route.name.includes('leeui')
})

// 检查是否为 Element 相关路由
const isElementRoute = computed(() => {
  return typeof route.name === 'string' && route.name.includes('element')
})
</script>

<style scoped>
.case-layout {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background-color: #f5f7fa;
}

/* 头部样式 */
.case-header {
  background-color: #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-content {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 64px;
}

.logo {
  margin: 0;
  font-size: 1.4rem;
  font-weight: 600;
}

.logo-link {
  color: #1890ff;
  text-decoration: none;
}

/* 导航菜单样式 */
.nav-container {
  display: flex;
  align-items: center;
  gap: 24px;
}

.nav-link {
  color: #333;
  text-decoration: none;
  font-size: 1rem;
  padding: 8px 0;
  position: relative;
  transition: color 0.3s;
}

.nav-link:hover {
  color: #1890ff;
}

.nav-link.active {
  color: #1890ff;
}

.nav-link.active::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 2px;
  background-color: #1890ff;
  border-radius: 1px;
}

/* 下拉菜单样式 */
.dropdown-link {
  color: #333;
  font-size: 1rem;
  padding: 8px 0;
  cursor: pointer;
  position: relative;
  display: flex;
  align-items: center;
  gap: 4px;
  transition: color 0.3s;
}

.dropdown-link:hover {
  color: #1890ff;
}

.dropdown-link.active {
  color: #1890ff;
}

.dropdown-link.active::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 2px;
  background-color: #1890ff;
  border-radius: 1px;
}

.icon-arrow {
  font-size: 14px;
  transition: transform 0.3s;
}

.el-dropdown-open .icon-arrow {
  transform: rotate(180deg);
}

/* 下拉菜单项样式 */
.el-dropdown-menu {
  border-radius: 6px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
  padding: 8px 0;
}

.el-dropdown-item {
  padding: 8px 20px;
  transition: background-color 0.2s;
}

.el-dropdown-item:hover {
  background-color: #f5f7fa;
}

.el-dropdown-item a {
  color: #333;
  text-decoration: none;
  display: block;
}

/* 主要内容区样式 */
.case-main {
  flex: 1;
  padding: 30px 0;
}

.case-container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 20px;
}

.page-header {
  margin-bottom: 24px;
}

.page-title {
  margin: 0 0 8px 0;
  font-size: 1.8rem;
  color: #1f2329;
  font-weight: 600;
}

.page-desc {
  margin: 0;
  color: #666;
  font-size: 1rem;
}

.case-content {
  background-color: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
  padding: 24px;
  transition: all 0.3s ease;
}

.case-content:hover {
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
}

/* 页脚样式 */
.case-footer {
  background-color: #fff;
  padding: 20px 0;
  text-align: center;
  color: #666;
  font-size: 0.9rem;
  border-top: 1px solid #eee;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .header-content {
    height: 56px;
  }
  
  .logo {
    font-size: 1.2rem;
  }
  
  .nav-container {
    gap: 16px;
  }
  
  .case-main {
    padding: 20px 0;
  }
  
  .case-content {
    padding: 16px;
  }
  
  .page-title {
    font-size: 1.5rem;
  }
}

/* 下拉菜单容器样式 */
.custom-dropdown-menu {
  border: none;
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
  padding: 6px 0;
  margin-top: 4px;
  overflow: hidden;
}

/* 下拉菜单项样式 */
.custom-dropdown-item {
  padding: 10px 16px;
  margin: 0;
  font-size: 14px;
  transition: all 0.2s ease;
}

/* 解决链接默认样式问题 */
.dropdown-item-link {
  color: #333; /* 文字颜色改为深灰色 */
  text-decoration: none; /* 移除下划线 */
  display: block;
  width: 100%;
  height: 100%;
}

/* 悬停效果优化 */
.custom-dropdown-item:hover {
  background-color: #f0f7ff; /* 淡蓝色背景 */
}

.custom-dropdown-item:hover .dropdown-item-link {
  color: #1890ff; /* 悬停时文字变为主色调 */
}

/* 当前激活项样式 */
.custom-dropdown-item.active,
.custom-dropdown-item.active .dropdown-item-link {
  background-color: #e6f7ff;
  color: #1890ff;
}

/* 下拉菜单箭头样式优化 */
.icon-arrow {
  font-size: 14px;
  transition: transform 0.3s ease;
}

.el-dropdown-open .icon-arrow {
  transform: rotate(180deg);
}

/* 移除所有链接的默认焦点样式 */
.dropdown-item-link:focus,
.nav-link:focus,
.logo-link:focus {
  outline: none;
  text-decoration: none;
}

/* 访问过的链接样式保持不变 */
.dropdown-item-link:visited {
  color: #333;
}
</style>